using UnityEngine;

public class PlayerController : MonoBehaviour
{
	[Header("移动速度")]
	public float speed = 1000;
	public Rigidbody2D player;
	private Vector3 targetPos;
	// 初始位置
	private Vector3 orgPos;
	public Camera cam;
	private bool isMove;
	private bool movable;
	public ScoreManager scoreManager;

	public float killMonsterGetScore = 1.0f;
	
	void Start()
	{
		// 刚进入游戏设置不可动
		movable = false;
		isMove = false;
		targetPos = player.transform.position;
		orgPos = player.transform.position;
	}
 
	void Update()
	{
		GetComponent<Animator>().speed = movable ? 1 : 0;
		Movement();
	}
	private void Movement()
	{
		if (!movable)
		{
			return;
		}

#if UNITY_STANDALONE_WIN
         		targetPos = Input.mousePosition;
         		targetPos = cam.ScreenToWorldPoint(targetPos);
         		targetPos.z = player.transform.position.z;
                
#endif
         		float step = speed * Time.deltaTime;  
         		//player.transform.position = Vector3.MoveTowards(player.transform.position, targetPos, step);
                player.MovePosition(Vector3.MoveTowards(player.transform.position, targetPos, step));
	}

	public void changeMovable(bool flag)
	{
		movable = flag;
	}

	public void resetPlayer()
	{
		changeMovable(true);
	}

	public void initPlayer()
	{
		changeMovable(false);
		player.transform.position = orgPos;
	}

	public void killMonster()
	{
		// 增加分数
		scoreManager.addScore(killMonsterGetScore);
	}

}
 	